/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.alarm;

import com.ttt.nor2.config.CfgAlarm;
import com.ttt.nor2.util.ExceptionUtil;
import java.io.File;

import org.apache.log4j.Logger;
import org.jdom.Document;

import org.jdom.Element;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author anuphabm
 */
public abstract class MsgExchage {

    private Logger logger = Logger.getLogger(MsgExchage.class);
    protected CfgAlarm cfg;
    protected String data;

    public MsgExchage() {
    }

    public void setCfg(CfgAlarm cfg) {
        this.cfg = cfg;
    }

    public void readAlarmFromFile2String() {
        // Build the document with SAX and Xerces, no validation
        SAXBuilder builder = new SAXBuilder();
        try {
            // Create the document
            Document doc = builder.build(new File(cfg.getPathProcess() + cfg.getFilename()));
            Element root = doc.getRootElement();
            data = root.getChild("data").getText();
            logger.info("data from file alarm [" + data + "]");
        } catch (Exception ex) {
            logger.error("Exception read xml error! " + ExceptionUtil.getStackTrace(ex));
        }

    }

    public void deleteFile(){
        File pc = new File(cfg.getPathProcess() + cfg.getFilename());//source
        pc.delete();
        logger.info("Delete file [" + cfg.getPathProcess() + cfg.getFilename());
    }

    public abstract boolean isSavedata();


}
